﻿/// Write a program that can solve these tasks:
/// Reverses the digits of a number
/// Calculates the average of a sequence of integers
/// Solves a linear equation a * x + b = 0
///		Create appropriate methods.
///		Provide a simple text-based menu for the user to choose which task to solve.
///		Validate the input data:
/// The decimal number should be non-negative
/// The sequence should not be empty
/// a should not be equal to 0


using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        PrintMenu();
        int n;
        int.TryParse(Console.ReadLine(), out n);

        while (n != 0 || n != 1 || n != 2 || n != -1)
        {
            if (n == 0)
            {
                InputReverseDigits();
            }
            else if (n == 1)
            {
                 InputAverage();
            }
            else if (n == 2)
            {
                InputEquation();
            }
            else if (n == -1)
            {
                break;
            }

            Console.WriteLine();
            PrintMenu();
            int.TryParse(Console.ReadLine(), out n);
        }

        Console.WriteLine();
    }

    private static void PrintMenu()
    {
        Console.WriteLine("|............................................|");
        Console.WriteLine("|............................................|");
        Console.WriteLine("| Please Select:                             |");
        Console.WriteLine("|............................................|");
        Console.WriteLine("| 0: Reverse Digits Order - default          |");
        Console.WriteLine("|............................................|");
        Console.WriteLine("| 1: Get Average of a Sequence of Integers   |");
        Console.WriteLine("|............................................|");
        Console.WriteLine("| 2: Solve Linear Equation => a * x + b = 0  |");
        Console.WriteLine("|............................................|");
        Console.WriteLine("|-1: For Exit the Program                    |");
        Console.WriteLine("|............................................|");
        Console.WriteLine("|............................................|");
    }

    static int ReverseNumber(int number)
    {
        int reversed = 0;
        int temp = number;
        int counrt = 0;

        while (number >= 10)
        {
            temp = number % 10;
            number = number / 10;
            reversed += temp * (int)Math.Pow(10, number.ToString().Length);
            counrt++;
        }
        if (counrt > 0)
        {
            return reversed + number;
        }
        else
        {
            return number;
        }

    }

    static double GetAverage(List<int> list)
    {
        int sum = 0;

        for (int i = 0; i < list.Count; i++)
        {
            sum += list[i];
        }

        return (double)sum / list.Count;
    }

    static double CalculateEquation(int a, int b)
    {
        return (double)-b / a;
    }


    static void InputReverseDigits()
    {
        Console.WriteLine("Enter number:");

        int n = int.Parse(Console.ReadLine());

        if (n >= 0) Console.WriteLine("ReverseDigits: " + ReverseNumber(n));
        else Console.WriteLine("Number should be non-negative.");
    }

    static void InputAverage()
    {
        Console.WriteLine("Enter numbers:");
        int n;
        List<int> list = new List<int>();
        string input = Console.ReadLine();

        while (true)
        {
            if (input == "")
            {
                break;
            }
            else
            {
                int.TryParse(input, out n);
                list.Add(n);
                input = Console.ReadLine();
            } 
        }

        Console.WriteLine("GetAverage: " + GetAverage(list));
    }

    static void InputEquation()
    {
        Console.WriteLine("Enter a and b:");

        int a = int.Parse(Console.ReadLine());
        int b = int.Parse(Console.ReadLine());

        if (a != 0)
        {
            Console.WriteLine("x =  " + CalculateEquation(a, b));
        }
        else
        {
            Console.WriteLine("Coefficient 'a' should not be zero.");
        }
    }

    
}